home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / share / tod / setup.exe / hiscore.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-12  |  4.5 KB  |  139 lines

  1. /**************************************\
  2. * hiscore.c                            *
  3. * High score file routines             *
  4. *                                      ********************************\
  5. * Copyright 2000 Damian Yerrick                                        *
  6. *                                                                      *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; either version 2 of the License, or    *
  10. * (at your option) any later version.                                  *
  11. *                                                                      *
  12. * This program is distributed in the hope that it will be useful,      *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
  15. * GNU General Public License for more details.                         *
  16. *                                                                      *
  17. * You should have received a copy of the GNU General Public License    *
  18. * along with this program; if not, write to the Free Software          *
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
  20. * Or view the License online at http://www.gnu.org/copyleft/gpl.html   *
  21. *                                                                      *
  22. * Damian Yerrick's World Wide Web pages are located at                 *
  23. *   http://www.PinEight.com                                            *
  24. *                                                                      *
  25. \**********************************************************************/
  26.  
  27. #include "hiscore.h"
  28. #include "allegdlg.h"
  29.  
  30.  
  31. /* Private data structures */
  32.  
  33. typedef struct HiPlayer
  34. {
  35.   char playerName[20];
  36.   unsigned int password; /* CRC-32 of player's password */
  37.   unsigned int nGames;
  38. } HiPlayer;
  39.  
  40. /* basic disk format of HiPlayer data structure:
  41.    All ints are big-endian.
  42.    (I'm not telling you how it's encrypted; you'll have to read the
  43.    fucking source for that.)
  44.  
  45. (4 bytes) crc-32 of following data, big-endian
  46. (4 to 17 bytes) playerName, null terminated
  47. (4 bytes) password
  48. (4 bytes) game ID
  49.  
  50. */
  51.  
  52.  
  53. /* Private globals */
  54.  
  55. static HiPlayer *curPlayer = 0;
  56.  
  57. unsigned long curPlayerFilename = 0;
  58. /* How the fuck are you storing the filename in a long?
  59.  *
  60.  * It's easy: the filename is the hex of the crc32 of the player's name.
  61.  * sprintf(filename, "%08lx.ljp", strcrc(playerName, 16));
  62.  */
  63. char playersPath[256];
  64. DATAFILE *theData;
  65. BITMAP *todlogo, *spin8;
  66. int loggedIn = 0;
  67.  
  68. int InitScore(DATAFILE *dat)
  69. {
  70.   char buf1[256];
  71.   DATAFILE *obj;
  72.                            
  73.   get_executable_name(buf1, 255);
  74.   replace_filename(playersPath, buf1, "plyr/", 255);
  75.  
  76.   obj = find_datafile_object(dat, "LOGIN_BMP");
  77.   if(!obj)
  78.     return -1;
  79.   todlogo = obj->dat;
  80.  
  81.   obj = find_datafile_object(dat, "SPIN8");
  82.   if(!obj)
  83.     return -1;
  84.   spin8 = obj->dat;
  85.  
  86.  
  87.  
  88.   return 0;
  89. }
  90.  
  91.  
  92. /* LoginDialog() ***********************
  93.  * Presents a player login dialog box.
  94.  * Returns -1 for cancel or 0 for enter.
  95.  */
  96. static int LoginDialog(char *aimsn, char *pass)
  97. {
  98.   DIALOG dlg[] =
  99.   {
  100.    /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key) (flags)  (d1)  (d2)  (dp) */
  101.    { d_box_proc,        0,    0,    320,  200,  0,    0,    0,    0,       0,    0,    NULL },
  102.    { d_button_proc,     170,  184,  60,   12,   63,   0,    27,   D_EXIT,  0,    0,    "Cancel"},
  103.    { d_edit_proc,       128,  104,  136,  8,    63,   2,    'n',  D_EXIT,  16,   0,    aimsn},
  104.    { DY_pass_proc,      128,  116,  136,  8,    63,   2,    'p',  D_EXIT,  16,   0,    pass},
  105.    { d_text_proc,       24,   104,  104,  16,   63,   0,    0,    0,       0,    0,    "Screen &name:"},
  106.    { d_text_proc,       24,   116,  104,  16,   63,   0,    0,    0,       0,    0,    "&Password:"},
  107.    { DY_bitmap_proc,    0,    0,    320,  100,  63,   0,    0,    0,       0,    0,    todlogo },
  108.    { DY_idle_proc,      0,    0,    0,    0,    0,    0,    0,    0,       0,    0,    NULL },
  109.    { NULL,              0,    0,    0,    0,    0,    0,    0,    0,       0,    0,    NULL }
  110.   };
  111.  
  112.   int pressed;
  113.  
  114.   centre_dialog(dlg);
  115.  
  116.   pressed = do_dialog(dlg, 2);
  117.  
  118.   if(pressed == 1)
  119.     return -1;
  120.  
  121.   else
  122.     return 0;
  123. }
  124.  
  125. int Login(char *aimsn)
  126. {
  127.   char pass[17] = {0};
  128. //  int done;
  129.  
  130.   return LoginDialog(aimsn, pass);
  131. }
  132.  
  133. int AddScore(const HiGame *game)
  134. {
  135.   return -1;
  136. }
  137.  
  138.  
  139.